package com.maochang.pojo.util;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Data
public class Result1 {
    private  long   code;  //响应逻辑码 0 代表查询成功  -1失败
    private  long   count; //条数
    private  String  msg;  //信息
    private  Object  data; //数据
    //静态的构造方法
    public   static Result1 success1(Page<?> page){
        Result1 result=new Result1();
        result.setCode(0); //成功代表0
        result.setCount(Math.toIntExact(page.getTotal()));
        result.setData(page.getRecords());
        return result;
    };
    public   static Result1 successMsg(String msg){
        Result1 result=new Result1();
        result.setCode(1); //代表1
        result.setMsg(msg);
        return result;
    };
    public   static Result1 fail(String msg,Exception ex){
        Result1 result=new Result1();
        result.setCode(-1); //成功代表0
        result.setMsg(msg);
        log.error(msg,ex);
        return result;
    };

}
